package cn.itcast.bos.service.action.teke_delivary.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.domain.system.User;
import cn.itcast.bos.service.action.teke_delivary.PermissionService;
import cn.itcast.bos.web.Dao.teke_delivary.PermissionRepositoey;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {

	@Autowired
	private PermissionRepositoey permissionRepositoey;

	@Override
	public List<Permission> findByUser(User user) {

		if (user.getUsername().equals("admin")) {
			// 返回所有权限
			return permissionRepositoey.findAll();
		} else {
			// 根据用户调查
			return permissionRepositoey.findByUser(user.getId());
		}

	}

	// 添加权限
	@Override
	public void save(Permission model) {
		permissionRepositoey.save(model);
	}

	// 查询所有权限
	@Override
	public List<Permission> findAll() {

		return permissionRepositoey.findAll();
	}

	// 添加权限
	@Override
	public void saves(Permission model) {
		permissionRepositoey.save(model);
	}

}
